package com.kevin.spring;

import com.kevin.spring.aop.Common;
import com.kevin.spring.bean.FirstServiceBean;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;

/**
 * Created by loli on 2014/10/25.
 */
public class SpringDemo {
    public static Logger logger = Logger.getLogger(SpringDemo.class);
    public static void main(String []args) {

        Logger logger2 = Logger.getLogger(ClassPathResource.class);
        logger.debug("create new message");
        Resource resource = new ClassPathResource("spring.xml");
        BeanFactory factory = new XmlBeanFactory(resource);

        FirstServiceBean firstService = (FirstServiceBean)factory.getBean("firstServiceBean");
        System.out.println(firstService.sayHello("hello"));

        FirstServiceBean firstService2 = (FirstServiceBean)factory.getBean("firstServiceBean2");
        System.out.println(firstService2.sayHello("hello"));

        FirstServiceBean firstService3 = (FirstServiceBean)factory.getBean("firstServiceBean3");
        System.out.println(firstService3.sayHello("hello"));

        Common common = (Common)factory.getBean("common");

        common.execute("kevin", "oracle");

        ApplicationContext context = new ClassPathXmlApplicationContext("spring.xml");

        common = (Common)context.getBean("common");

        common.execute("kevin", "oracle");

    }
}
